/******************************************************************************
* file  : console.c
* creat : apleilx
* data  : 2021/01/20
*******************************************************************************/
#include "os_obj.h"
#include "sys_task.h"
#include "pincfg.h"
#include "com_obj.h"
#include "dataproc.h"
#include "common.h"
#include "simp_txt_analysis.h"
#include "str_ext.h"

extern const txt_cmd_cfg_type cmd_list[];

static uint8_t console_buff[1024];
void cmd_analysis(uint8_t *cmd);
void sys_ui_tst(void);
void console_event_send(uint16_t event);

/*****************************************************************************
* @brief   console task.
* @param   argument
* @return  none
*****************************************************************************/
void task_console(ULONG thread_input)
{
    uint16_t len;
	ULONG event;
	
	com.obj01.os_event_send = console_event_send;
	com.obj01.os_event_rcv_end = 1;
	com.obj01.os_event_timeout = 2;
	
    while (1)
    {
        len = com.obj01.fun->cycle_rcv_line(console_buff);

        if (len > 0)
        {
            str_remove_l20_ascii(console_buff);

            cmd_analysis(console_buff);
        }
		else
		{
			tx_event_flags_get(os_obj.eid_console,
							   0xFFFF, 
							   TX_OR_CLEAR,
							   &event,
							   TX_WAIT_FOREVER);			
		}
    }
}

/*****************************************************************************
* @brief   console_event_send.
* @param   event: event
* @return  none
*****************************************************************************/
void console_event_send(uint16_t event)
{
    tx_event_flags_set(os_obj.eid_console, event, TX_OR);
}

/*****************************************************************************
* @brief   cmd analysis.
* @param   cmd: cmd string
* @return  none
*****************************************************************************/
void cmd_analysis(uint8_t *cmd)
{
    int index;
    
	index = txt_cmd_analysis(cmd_list, (char *)cmd, 100);
    if (index > 0)
    {
    	NOP1();
		if(index > 2)
		{
			bcd_to_hex_u8(34);
		}
    }
    else
    {
       
    }
}


